﻿@using zichan.Entity
@using zichan.Common;
@model IPagedList<PutawayServer>
@{
    ViewBag.Title = "机柜管理列表";
}

@section Pagetitle{
    @AdminCommon.PageTitle("机柜管理列表", "添加/删除/修改")
}
<style>
    .c_Box {
        display: none;
    }

    #pagebar li {
        display: inline-block;
    }
</style>
<div class="portlet">
    <div class="portlet-title">
        <div class="caption ">
            <i class="fa fa-table"></i>机柜管理列表
        </div>
        <div class="actions pull-left leftMargin">
            @if (zichan.Common.PowerHelp.Check("Cabinet", "create"))
            {
                <a href="@Url.Action("create", "Cabinet")" class="btn default yellow-stripe">
                    <i class="fa fa-plus"></i>
                    <span class="hidden-480">添加机柜</span>
                </a>

            }
            @if (zichan.Common.PowerHelp.Check("Cabinet", "PutAway") && Model.Count() > 0)
            {
                <a href="@Url.Action("PutAway", "Cabinet")" class="btn default yellow-stripe">
                    <i class="fa fa-plus"></i>
                    <span class="hidden-480">上架服务器</span>
                </a>
            }
            @*@if (zichan.Common.PowerHelp.Check("Cabinet", "OldPutServer") && Model.Count() > 0)
                {
                    <a href="@Url.Action("OldPutServer", "Cabinet")" class="btn default yellow-stripe">
                        <i class="fa fa-plus"></i>
                        <span class="hidden-480">上架已有服务器</span>
                    </a>
                }*@
        </div>
    </div>
    <div class="portlet-body">
        <div class="table-container">
            <div class="dataTables_wrapper dataTables_extended_wrapper no-footer">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="table-group-actions pull-left">
                            @using (Html.BeginForm("index", "Cabinet", FormMethod.Get, new { @class = "form-inline" }))
                            {
                                <input type="hidden" name="pageSize" value="@ViewBag.pageSize" />
                                <div class="help-block">
                                    <div class="form-group">
                                        <input type="text" placeholder="请输入机柜名称" name="name" value="@ViewBag.name" class="form-control input-small input-sm" />
                                    </div>
                                    <div class="form-group">
                                        <input type="text" placeholder="请输入IP" name="Ip" value="@ViewBag.Ip" class="form-control input-small input-sm" />
                                    </div>
                                    <div class="form-group">
                                        @Html.DropDownList("machineRoomId", (SelectList)ViewBag.machineRoomIds, "全部机房", new { @class = "form-control input-small input-sm" })
                                    </div>
                                    <div class="form-group">
                                        @Html.DropDownList("cabinetClassId", (SelectList)ViewBag.cabinetClassIds, "用途", new { @class = "form-control input-small input-sm" })
                                    </div>
                                    @*<div class="form-group">
                                        @Html.DropDownList("serverPurposeSubId", (SelectList)ViewBag.serverPurposeSubIds, "详细用途", new { @class = "form-control input-small input-sm" })
                                    </div>*@
                                    <div class="form-group">
                                        <input type="text" placeholder="请输入备注关键字" name="keyWord" value="@ViewBag.keyWord" class="form-control input-small input-sm" />
                                    </div>
                                </div>
                                <div class="help-block">
                                    <div class="form-group">
                                        <input type="text" placeholder="请输入服务器编码" name="code" value="@ViewBag.code" class="form-control input-small input-sm" />
                                    </div>
                                    <div class="form-group">
                                        <input type="text" placeholder="请输入占位数" name="uNO" value="@ViewBag.uNO" class="form-control input-small input-sm" />
                                    </div>
                                    <div class="form-group">
                                        @Html.DropDownList("vacancy", (SelectList)ViewBag.vacancys, "全部空位", new { @class = "form-control input-small input-sm" })
                                    </div>
                                    <div class="form-group">
                                        @Html.DropDownList("companyId", (SelectList)ViewBag.companyIds, "全部公司", new { @class = "form-control input-small input-sm" })
                                    </div>
                                    <div class="form-group">
                                        @Html.DropDownList("statu", (SelectList)ViewBag.status, "全部状态", new { @class = "form-control input-small input-sm" })
                                    </div>
                                    <button class="btn btn-sm yellow table-group-action-submit"><i class="fa fa-check"></i> 搜索</button>
                                </div>
                            }
                        </div>
                    </div>
                </div>
                <div class="form-group"><h5>机柜总数:<span style="color:red;">@Model.Select(o => o.CabinetId).Distinct().Count()</span></h5></div>
                <div class="table-scrollable">
                    <table class="table  table-hover">
                        <thead>
                            <tr class="heading">
                                <th>机柜名称</th>
                                <th>空位</th>
                                <th>服务器编码</th>
                                <th>占位</th>
                                <th>所属机房</th>
                                <th>所属公司</th>
                                <th>用途</th>
                                <th>详细用途</th>
                                <th>IP</th>
                                <th>状态</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            @foreach (PutawayServer r in Model)
                            {
                                <tr>
                                    <td>@r.CabinetName</td>
                                    <td>
                                        @{ if (r.Statu == (int)ServerStatu.Remove)
                                            {
                                                @("-")
                                            }
                                            else
                                            {
                                                @r.Vacancy
                                            }
                                        }
                                    </td>
                                    <td>
                                        @(r.Code = r.Code ?? "-")
                                    </td>
                                    <td>
                                        @{ if (r.Statu == (int)ServerStatu.Free)
                                            {
                                                @("-")
                                            }
                                            else
                                            {
                                                @r.UseNumber
                                            }
                                        }
                                    </td>

                                    <td>@r.MachineRoomName</td>
                                    <td>@(r.CompanyName = r.CompanyName ?? "-")</td>
                                    <td>@(r.serverPurposeName = r.serverPurposeName ?? "-")</td>
                                    <td>@(r.serverPurposeSubName = r.serverPurposeSubName ?? "-")</td>
                                    <td id="IPs_@r.Id" class="IPS" onmouseover="return IpForm(@r.Id)" data-Ips="@r.SubIP">@(r.IP = r.IP ?? "-")</td>
                                    <td style="font-weight:bold; color:@(r.Statu==0?"#008F89":(r.Statu==1?"#FF6600":"#999999"))">@r.StatuName</td>
                                    <td>
                                        @if (PowerHelp.Check("Cabinet", "PutAwayEdit") && r.Statu == 0)
                                        {
                                            <a href="@Url.Action( "PutAway","Cabinet", new {machineRoomId=r.MachineRoomId, cabinetId = r.CabinetId })" class="btn default btn-xs purple">
                                                <i class="fa fa-edit"></i> 上架服务器
                                            </a>
                                        }
                                        @if (PowerHelp.Check("Cabinet", "OldPutServer") && r.Statu == 0)
                                        {
                                            <a href="@Url.Action( "OldPutServer","Cabinet", new {machineRoomId=r.MachineRoomId, cabinetId = r.CabinetId })" class="btn default btn-xs purple">
                                                <i class="fa fa-edit"></i> 上架已有服务器
                                            </a>
                                        }
                                        @if (PowerHelp.Check("Cabinet", "CabinetEdit") && r.Statu == 0)
                                        {
                                            <a href="@Url.Action("CabinetEdit", "Cabinet", new {id = r.CabinetId })" class="btn default btn-xs purple">
                                                <i class="fa fa-edit"></i> 编辑
                                            </a>
                                        }
                                        @if (PowerHelp.Check("Cabinet", "Delete") && r.Statu == 0 && !r.IsUsed.HasValue)
                                        {
                                            @*<a href="@Url.Action("delete", "Assetes", new { id = r.Id })" class="btn default btn-xs black">*@
                                            <a class="btn default btn-xs purple" href="javascript:if(confirm('确定要删除@(r.CabinetName)?'))location='/Cabinet/delete?id=@r.CabinetId'">
                                                <i class="fa fa-trash-o"></i> 删除
                                            </a>
                                        }
                                        @if (PowerHelp.Check("Cabinet", "Cancellation") && r.Statu == 0 && r.IsUsed.HasValue)
                                        {
                                            @*<a href="@Url.Action("Cancellation", "Assetes", new { id = r.Id })" class="btn default btn-xs black">*@
                                            <a class="btn default btn-xs purple" href="javascript:if(confirm('确定要报废@(r.CabinetName)?'))location='/Cabinet/Cancellation?id=@r.Id'">
                                                <i class="fa fa-trash-o"></i> 作废
                                            </a>
                                        }
                                        @if (PowerHelp.Check("Cabinet", "PutAwayEdit") && r.Statu == 1)
                                        {
                                            <a href="@Url.Action( "PutAwayEdit","Cabinet", new {id=r.Id })" class="btn default btn-xs purple">
                                                <i class="fa fa-edit"></i> 编辑
                                            </a>
                                        }
                                        @if (PowerHelp.Check("Cabinet", "OutOfRock") && r.Statu == 1)
                                        {
                                            <a href="@Url.Action("OutOfRock", "Cabinet", new {id=r.Id,cabinetId=r.CabinetId })" class="btn default btn-xs purple">
                                                <i class="fa fa-edit"></i> 下架
                                            </a>
                                        }
                                        @if (PowerHelp.Check("Cabinet", "Detail"))
                                        {
                                            <a href="@Url.Action("Detail", "Cabinet", new {id=r.Id })" class="btn default btn-xs purple">
                                                <i class="fa fa-search"></i> 详情
                                            </a>
                                        }
                                       
                                    </td>
                                </tr>
                                            }
                        </tbody>
                    </table>
                </div>
                @if (PowerHelp.Check("Excel", "CabinetExc"))
                {
                    <div class="row">
                        <div class="col-md-12">
                            <a href="@Url.Action("CabinetExc", "Excel", new {name=ViewBag.name, Ip=ViewBag.Ip, machineRoomId=ViewBag.machineRoomId, cabinetClassId=ViewBag.cabinetClassId,serverPurposeSubId=ViewBag.serverPurposeSubId, keyWord=ViewBag.keyWord, code=ViewBag.code, uNO=ViewBag.uNO, vacancy=ViewBag.vacancy, companyId=ViewBag.companyId, statu=ViewBag.statu,cabinetId=ViewBag.cabinetId,isNull=ViewBag.isNull })" class="btn default green">
                                <i class="fa fa-table"></i>
                                <span class="hidden-480">Excel导出报表</span>
                            </a>
                        </div>
                    </div>
                }
                <div class="row">
                    <div class="col-sm-12 dataTables_paginate">
                        <div class="pull-right">
                            <ul id="pagebar" style="display:inline-block;margin-right:10px;">
                                <li>
                                    每页<select name="pageSize" id="pageSize" class="select2" style="width:50px;font-size:18px;">
                                        <option value="@ViewBag.pageSize">@ViewBag.pageSize</option>
                                        @foreach (var s in ViewBag.pageSizes)
                                        {
                                            <option value="@s.Value">@s.Text</option>
                                        }
                                    </select>个
                                </li>
                                <li>第@(Model.PageNumber)/共@(Model.PageCount)页</li>
                                @using (Html.BeginForm("index", "Cabinet", FormMethod.Get, new { @style = "display: inline-block;" }))
                                {
                                    <li style="display:none;">
                                        <input type="hidden" name="pageSize" value="@ViewBag.pageSize" />
                                        <input type="hidden" name="name" value="@ViewBag.name" />
                                        <input type="hidden" name="Ip" value="@ViewBag.Ip" />
                                        <input type="hidden" name="machineRoomId" value="@ViewBag.machineRoomId" />
                                        <input type="hidden" name="cabinetClassId" value="@ViewBag.cabinetClassId" />
                                        <input type="hidden" name="serverPurposeSubId" value="@ViewBag.serverPurposeSubId" />
                                        <input type="hidden" name="keyWord" value="@ViewBag.keyWord" />
                                        <input type="hidden" name="uNO" value="@ViewBag.uNO" />
                                        <input type="hidden" name="vacancy" value="@ViewBag.vacancy" />
                                        <input type="hidden" name="code" value="@ViewBag.code" />
                                        <input type="hidden" name="companyId" value="@ViewBag.companyId" />
                                        <input type="hidden" name="statu" value="@ViewBag.statu" />
                                        <input type="hidden" name="cabinetId" value="@ViewBag.cabinetId" />
                                        @Html.TextBox("pageCount", Model.PageCount)
                                    </li>
                                    <li>跳转至<input name="selectedPage" style="width:40px;font-size:18px;" value="@ViewBag.selectedPage" />页</li>
                                    <li><button type="submit">GO</button></li>}
                            </ul>
                            @if (Model.PageCount > 1)
                            {
                                <ul id="pagebar" class="pagination" style="margin:0px;float:right;">
                                    <li><a href="@Url.Action("Index", "Cabinet", new { code = ViewBag.code, name = ViewBag.name, statu = ViewBag.statu, keyWord = ViewBag.keyWord, Ip = ViewBag.Ip, machineRoomId = ViewBag.machineRoomId, cabinetClassId = ViewBag.cabinetClassId, serverPurposeSubId=ViewBag.serverPurposeSubId,vacancy = ViewBag.vacancy, companyId = ViewBag.companyId, uNO = ViewBag.uNO, cabinetId = ViewBag.cabinetId,pageSize = ViewBag.pageSize, page = 1 })">首页</a></li>
                                    <li>@Html.ActionLink("上一页", "Index", "Cabinet", new { code = ViewBag.code, name = ViewBag.name, statu = ViewBag.statu, keyWord = ViewBag.keyWord, Ip = ViewBag.Ip, machineRoomId = ViewBag.machineRoomId, cabinetClassId = ViewBag.cabinetClassId, serverPurposeSubId = ViewBag.serverPurposeSubId, vacancy = ViewBag.vacancy, companyId = ViewBag.companyId, uNO = ViewBag.uNO, cabinetId = ViewBag.cabinetId, pageSize = ViewBag.pageSize, page = Model.PageNumber - 1 }, null)</li>
                                    <li>@Html.ActionLink("下一页", "Index", "Cabinet", new { code = ViewBag.code, name = ViewBag.name, statu = ViewBag.statu, keyWord = ViewBag.keyWord, Ip = ViewBag.Ip, machineRoomId = ViewBag.machineRoomId, cabinetClassId = ViewBag.cabinetClassId, serverPurposeSubId = ViewBag.serverPurposeSubId, vacancy = ViewBag.vacancy, companyId = ViewBag.companyId, uNO = ViewBag.uNO, cabinetId = ViewBag.cabinetId, pageSize = ViewBag.pageSize, page = (Model.PageNumber + 1 < Model.PageCount ? Model.PageNumber + 1 : Model.PageCount) }, null)</li>
                                    <li>@Html.ActionLink("末页", "Index", "Cabinet", new { code = ViewBag.code, name = ViewBag.name, statu = ViewBag.statu, keyWord = ViewBag.keyWord, Ip = ViewBag.Ip, machineRoomId = ViewBag.machineRoomId, cabinetClassId = ViewBag.cabinetClassId, serverPurposeSubId = ViewBag.serverPurposeSubId, vacancy = ViewBag.vacancy, companyId = ViewBag.companyId, uNO = ViewBag.uNO, cabinetId = ViewBag.cabinetId, pageSize = ViewBag.pageSize, page = Model.PageCount }, null)</li>
                                </ul>}
                        </div>

                    </div>
                </div>

            </div>

        </div>
    </div>
</div>

@section footer{
    <script src="/assets/global/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
    <script src="~/Scripts/AssetJs.js"></script>
    <script type="text/javascript">
        var formatDateTime = function (date) {
            var y = date.getFullYear();
            var m = date.getMonth() + 1;
            var d = date.getDate();
            return y + '/' + m + '/' + d;
        };
        $('.dateSdt').datetimepicker({
            //language: 'zh-CN',
            weekStart: 1,
            todayBtn: 0,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            forceParse: 0,
            minView: 'month',　　　　//日期时间选择器所能够提供的最精确的时间选择视图。
            format: 'yyyy/m/d'
        }).on('changeDate', function (ev) {
            $("#sdt").val(formatDateTime(new Date(ev.date.valueOf() - 28800000)));
        });
        $('.dateEdt').datetimepicker({
            //language: 'zh-CN',
            weekStart: 1,
            todayBtn: 0,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            forceParse: 0,
            minView: 'month',　　　　//日期时间选择器所能够提供的最精确的时间选择视图。
            format: 'yyyy/m/d'
        }).on('changeDate', function (ev) {
            $("#edt").val(formatDateTime(new Date(ev.date.valueOf() - 28800000)));
        });
        $(function () {
            $('#pageSize').on("change", function () {
                var name = $("input[name='name']").val();
                var statu = $("input[name='statu']").val();
                var keyWord = $("input[name='keyWord']").val();
                var code = $("input[name='code']").val();
                var Ip = $("input[name='Ip']").val();
                var machineRoomId = $("input[name='machineRoomId']").val();
                var cabinetClassId = $("input[name='cabinetClassId']").val();
                var serverPurposeSubId = $("input[name='serverPurposeSubId']").val();
                var uNO = $("input[name='uNO']").val();
                var vacancy = $("input[name='vacancy']").val();
                var companyId = $("input[name='companyId']").val();
                var cabinetId = $("input[name='cabinetId']").val();
                var size = $(this).val();
                location.href = "/Cabinet/Index?name=" + name + "&Ip=" + Ip + "&machineRoomId=" + machineRoomId + "&cabinetClassId=" + cabinetClassId +"&serverPurposeSubId=" + serverPurposeSubId + "&keyWord=" + keyWord + "&code=" + code + "&uNO=" + uNO + "&vacancy=" + vacancy + "&companyId=" + companyId + "&statu=" + statu + "&cabinetId=" + cabinetId + "&pageSize=" + size;
            });
            var layer = $("<div id='layer' onmouseout='return CloseForm()'>");
            $("body").append(layer);
        });
        //function IpForm(id) {
        //    //var id = $(this).attr("date-id");
        //    var IpID = '#IPs_' + id;
        //    var Ip = "主IP：" + $(IpID).html();
        //    var subIp = "辅IP：" + $(IpID).attr("data-Ips").replace(/[,]/g, "<br/>");
        //    //alert(subIp);
        //    if (subIp.length > 4) {
        //        var x = $(IpID).offset().top;
        //        var y = $(IpID).offset().left;
        //        var width = $(IpID).width();
        //        var height = $(IpID).parent("tr").height();
        //        $("#layer").html(Ip + "<br>" + subIp);
        //        $("#layer").css({
        //            "position": "absolute",
        //            "display": "block",
        //            "background-color": "#f3f3f3",
        //            "z-index": 20000,
        //            "width": width,
        //            "min-height": height,
        //            "top": x,
        //            "left": y
        //        });
        //    }
        //};
        function CloseForm() {
            $("#layer").css("display", "none");
        }
    </script>
}
